package cn.dotalk.usermanage.controller;

import cn.dotalk.usermanage.utils.ResultMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * redis 测试
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/api/redis-t")
public class RedisTController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/set")
    public boolean set(){

        ValueOperations valueOperations = stringRedisTemplate.opsForValue();
        return valueOperations.setIfAbsent("user_manage_name","ddd");
    }

    @RequestMapping("/get")
    public String get(){

        ValueOperations valueOperations = stringRedisTemplate.opsForValue();
        return valueOperations.get("user_manage_name").toString();
    }


    @RequestMapping("/keys")
    public Object keys(){
        return ResultMsg.success(stringRedisTemplate.keys("*"));
    }


}
